package com.dlu.safe_construction.controller;

import com.dlu.safe_construction.common.ApiResult;
import com.dlu.safe_construction.dto.AreaInfoDTO;
import com.dlu.safe_construction.dto.AreaNumDTO;
import com.dlu.safe_construction.model.Area;
import com.dlu.safe_construction.model.Space;
import com.dlu.safe_construction.service.AreaService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by  lijiaxing on 2022/3/30 20:24
 *
 * @author lijiaxing
 */
@CrossOrigin
@RestController
@RequestMapping("/area")
@Slf4j
@Api(value = "片区Controller", tags = {"片区访问接口"})
public class AreaController implements BaseController {
    @Resource
    private AreaService areaService;

    @ApiOperation("插入一个新片区")
    @ApiResponses(value = {@ApiResponse(code = 0, message = "成功")})
    @PostMapping(path = "/add.json", produces = APPLICATION_JSON)
    public ApiResult<Void> add(@ApiParam("片区实体对象") @RequestBody Area area) {
        return areaService.add(area);
    }

    @GetMapping(path = "/delete.json", produces = APPLICATION_JSON)
    public ApiResult<Void> delete(String areaId) {
        return areaService.deleteById(areaId);
    }

    @GetMapping(path = "/list.json", produces = APPLICATION_JSON)
    public ApiResult<List<Area>> list() {
        return areaService.list();
    }

    @GetMapping(value = "/searchByAreaId.json", produces = APPLICATION_JSON)
    public ApiResult<AreaInfoDTO> searchByAreaId(String areaId) {
        return areaService.searchByAreaId(areaId);
    }

    @GetMapping(value = "/countAll.json", produces = APPLICATION_JSON)
    public ApiResult<AreaNumDTO> countAll() {
        return areaService.countAll();
    }
}
